/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.customer.export;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.customer.export.CustomerExportLog;
import com.server.modules.sys.service.customer.export.CustomerExportLogService;

/**
 * 客户导出日志Controller
 * @author 丁光彪
 * @version 2016-11-08
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/customer/export/customerExportLog")
public class CustomerExportLogController extends BaseController {

	@Autowired
	private CustomerExportLogService customerExportLogService;
	
	@ModelAttribute
	public CustomerExportLog get(@RequestParam(required=false) String id) {
		CustomerExportLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = customerExportLogService.get(id);
		}
		if (entity == null){
			entity = new CustomerExportLog();
		}
		return entity;
	}
	
	/*@RequiresPermissions("sys:customer:export:customerExportLog:view")*/
	@RequestMapping(value = {"list", ""})
	public String list(CustomerExportLog customerExportLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CustomerExportLog> page = customerExportLogService.findPage(new Page<CustomerExportLog>(request, response), customerExportLog); 
		model.addAttribute("page", page);
		model.addAttribute("customerExportLog", customerExportLog);
		return "modules/sys/customer/export/customerExportLogList";
	}

	/*@RequiresPermissions("sys:customer:export:customerExportLog:view")*/
	@RequestMapping(value = "form")
	public String form(CustomerExportLog customerExportLog, Model model) {
		model.addAttribute("customerExportLog", customerExportLog);
		return "modules/sys/customer/export/customerExportLogForm";
	}

	/*@RequiresPermissions("sys:customer:export:customerExportLog:edit")*/
	@RequestMapping(value = "save")
	public String save(CustomerExportLog customerExportLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, customerExportLog)){
			return form(customerExportLog, model);
		}
		customerExportLogService.save(customerExportLog);
		addMessage(redirectAttributes, "保存客户导出日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/customer/export/customerExportLog/?repage";
	}
	
	/*@RequiresPermissions("sys:customer:export:customerExportLog:edit")*/
	@RequestMapping(value = "delete")
	public String delete(CustomerExportLog customerExportLog, RedirectAttributes redirectAttributes) {
		customerExportLogService.delete(customerExportLog);
		addMessage(redirectAttributes, "删除客户导出日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/customer/export/customerExportLog/?repage";
	}

}